﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace _04.QueueBFS
{
    class Graph
    {
        private List<int>[] childNodes;

        public Graph(List<int>[] childNodes)
        {
            this.childNodes = childNodes;
        }

        public int NodesCount
        {
            get { return childNodes.Length; }
        }

        public void QueueBFS(int node)
        {
            bool[] visited = new bool[this.childNodes.Length];
            Queue<int> queue = new Queue<int>();
            queue.Enqueue(node);
            visited[node] = true;

            while (queue.Count > 0)
            {
                int current = queue.Dequeue();

                Console.WriteLine("Visited node {0}", current);

                foreach (var child in this.childNodes[current])
                {
                    if (!visited[child])
                    {
                        queue.Enqueue(child);
                        visited[child] = true;
                    }
                }
            }
        }
    }
}
